package com.ziyun.erp.web.modules.unitLibrary.controller;

import java.util.Arrays;
import java.util.Map;

import com.utility.StringUtils;
import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.utils.UserUtil;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.unitLibrary.entity.UnitLibraryEntity;
import com.ziyun.erp.modules.unitLibrary.service.UnitLibraryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author xueqz
 * @email 
 * @date 2018-12-07 13:57:48
 */
@RestController
@RequestMapping("unitLibrary/unitlibrary")
public class UnitLibraryController {
    @Autowired
    private UnitLibraryService unitLibraryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("unitLibrary:unitlibrary:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = unitLibraryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("unitLibrary:unitlibrary:info")
    public R info(@PathVariable("id") Integer id){
        UnitLibraryEntity unitLibrary = unitLibraryService.selectById(id);

        return R.ok().put("unitLibrary", unitLibrary);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("unitLibrary:unitlibrary:save")
    public R save(@RequestBody UnitLibraryEntity unitLibrary){

        unitLibrary.setCreateName(UserUtils.getCurentUser().getUsername());
        unitLibraryService.insert(unitLibrary);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("unitLibrary:unitlibrary:update")
    public R update(@RequestBody UnitLibraryEntity unitLibrary){
        ValidatorUtils.validateEntity(unitLibrary);
        unitLibrary.setUpdateName(UserUtils.getCurentUser().getUsername());
        unitLibraryService.updateAllColumnById(unitLibrary);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("unitLibrary:unitlibrary:delete")
    public R delete(@RequestBody Integer[] ids){
        Integer num = unitLibraryService.flagDelete(ids,UserUtils.getCurentUser().getUsername());
        return R.ok();
    }

}
